<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>消息列表</title>

<style>
.pagination .active a {
	/*background-color: #CC0041;
	color:white;*/
}
</style>

</head>

<body>

	<div class="container-fluid">
		<div id="market" class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">消息管理</a> <span class="divider">/</span></li>
					<li><a href="#">消息列表</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-th"></i> 消息列表
					</h2>

					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div id="search-form">
						<form id="searchForm" method="post" class="form-search span12" action="<c:url value="/admin/message/search"/>">
							<input type="hidden" name="pageNum" id="pageNum" value="${searchForm.pageNum }">
							<input type="hidden" name="messageId" id="messageId" value="0">
							<input type="hidden" name="flag" id="flag" value="0">
							<select id="messageType" class="input-meidum" name="messageType">
								<option value="-1" <c:if test="${searchForm.messageType == -1}">selected</c:if>>全部</option>
								<option value="0" <c:if test="${searchForm.messageType == 0}">selected</c:if>>系统消息</option>
								<option value="1" <c:if test="${searchForm.messageType == 1}">selected</c:if>>提醒消息</option>
								<option value="2" <c:if test="${searchForm.messageType == 2}">selected</c:if>>私信消息</option>
							</select>
							
							<button type="button" id="searchBtn" class="btn">&nbsp;&nbsp;搜索&nbsp;&nbsp;</button>
							<button type="button" id="newBtn" class="btn btn-danger pull-right">添加用户</button>
						</form>

					</div>
					<table id="userInfo" class="table table-striped table-bordered ">
						<thead>
							<tr>
								<th width="30">序号</th>
								<th>发送者</th>
								<th>接收者</th>
								<th>发送时间</th>
								<th>消息类型</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="message" items="${pageModel.result }" varStatus="status">
								<tr>
									<td>${status.index+1 }</td>
									<td>${message.fromUserName }</td>
									<td>${message.toUserName } </td>
									<td>${message.sendTime } </td>
									<td>${message.messageType == 0 ? "系统消息" : (message.messageType == 1 ? "提醒消息":"私信") }</td>
									<td>${message.status == 0 ? "正常" : "删除 " }</td>
									
									<td>
										<a href="javascript:view('${message.messageId }')">查看</a>&nbsp;&nbsp; 
										<a href="javascript:del('${message.messageId }',0)">删除</a>&nbsp;&nbsp; 
										<a href="javascript:recover('${message.messageId }')">恢复</a>&nbsp;&nbsp; 
										<a href="javascript:del('${message.messageId }',1)">彻底删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<div id="mypager" class="mypager"></div>
				</div>
			</div>
		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="../frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
	
	var pageNum = "${pageModel.pageNum}";
	var totalPage = "${pageModel.totalPage}";
	var numPerPage = "${pageModel.numPerPage}";
	
	$(document).ready(function(){
		
		$("#newBtn").click(function(){
			//跳转至新增页面
			window.location.href = '<c:url value="/admin/message/addMessage" />';
		})
		
		$('#mypager').bootstrapPaginator({
			currentPage:pageNum,
			totalPages:totalPage,
			numberOfPages:numPerPage,
			onPageClicked:function(event, originalEvent, type,page){
				$("input[name='pageNum']").val(page);
				$("#searchForm").submit();
			}
		});
		
		$("#messageType").change(function(){
			$("#searchForm").submit();
		})
		
		$('#searchBtn').click(function(){
			$("#searchForm").submit();
		})
	})
	
	function view(messageId){
		window.location.href = '<c:url value="/admin/message/viewMessage?messageId='+messageId+'"/>';
	}
	
	function del(messageId,flag){
		if(confirm("确定要删除吗？")){
			$("input[name='messageId']").val(messageId);
			$("input[name='flag']").val(flag);
			$("#searchForm").submit();
		}
	}
	
	function recover(messageId){
		window.location.href = '<c:url value="/admin/message/recoverMessage?messageId='+messageId+'"/>';
	}
	</script>
</body>
</html>
